package com.zyy.ui.policy.controller;

import com.zyy.ui.dto.ResultDTO;
import com.zyy.ui.policy.dto.AcceptDTO;
import com.zyy.ui.policy.dto.PolicyDTO;
import com.zyy.ui.policy.service.PolicyService;
import com.zyy.ui.utils.LogUtil;
import com.zyy.ui.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @ClassName: PolicyController
 * @Description: 投保类
 * @Author: zyy
 * @Date: 2020/04/25 18:36
 * @Version: 1.0
 */
@RestController
@RequestMapping("/policy")
@Api(tags = "01-出单接口")
@Validated
public class PolicyController {
    private PolicyService policyService;

    @Autowired
    public void setPolicyService(PolicyService policyService) {
        this.policyService = policyService;
    }

    @ApiOperation(value = "测试第一个接口")
    @PostMapping("/hello")
    public ResultDTO<String> hello(@RequestParam @ApiParam("描述")
                                   @Valid @NotBlank(message = "入参不可为空") String describe) {
        LogUtil.info("入参", describe);
        return ResultUtil.getSuccessResult(describe);
    }

    @ApiOperation(value = "投保接口")
    @PostMapping("/insure")
    public ResultDTO<String> insure(@Valid @RequestBody PolicyDTO policyDTO) {
        LogUtil.info("入参", policyDTO);
        return ResultUtil.getSuccessResult(null);
    }

    @ApiOperation(value = "承保接口")
    @PostMapping("/accept")
    public ResultDTO<String> accept(@RequestBody AcceptDTO acceptDTO) {
        LogUtil.info("入参", acceptDTO);
        policyService.accept(acceptDTO);
        return ResultUtil.getSuccessResult(null);
    }

}
